import {Component, Input, Type} from "@angular/core";
import {EmojiService} from "../../services/EmojiService";
import {ViewController, NavParams} from "ionic-angular";
import {IRichTextProvider} from "../rich-text-viewer/rich-text-viewer";

@Component({
  selector: 'emoji',
  templateUrl: 'emoji.html',
  providers: [EmojiService]
})
export class Emoji {
  emojiClass: Array<string> = [];
  private _emojiName: string;

  private _size: number = 64;

  @Input()
  get size(): number {
    return this._size;
  }
  set size(value) {
    this._size = value;
    this.zoom = value / 64;
  }

  zoom: number = 1;
  constructor(public viewCtrl: ViewController, public navParam: NavParams, private emojiService: EmojiService) {
    this.size = 32;
  }

  @Input()
  get name(): string {
    return this._emojiName;
  }
  set name(value: string) {
    this.emojiService.getEmojiId(value).then(emoji_id => {
      this.emojiClass = ['emojione', 'emojione-'+emoji_id];
    });
    this._emojiName = value;
  }
}


export class EmojiRichProvider extends IRichTextProvider {
  constructor() {super()}
  resolve(ele): Type<Emoji> {
    if (ele === 'emoji') return Emoji;
    return null;
  }
}
